package com.daocao.jy.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.daocao.jy.R;
import com.daocao.jy.activity.VipPacketActivity;
import com.daocao.jy.constant.UserInfoGlobal;
import com.daocao.jy.util.UI;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 18-4-24.
 */

public class VipPacketThreeFragment extends BaseFragment {
    Unbinder unbinder;
    @BindView(R.id.btn_login)
    TextView btnLogin;
    @BindView(R.id.img_icon_login)
    ImageView imgIconLogin;
    @BindView(R.id.img_icon)
    FrameLayout imgIcon;
    @BindView(R.id.txt_name)
    TextView txtName;
    @BindView(R.id.layout_vip)
    LinearLayout layoutVip;
    @BindView(R.id.txt_info_one)
    TextView txtInfoOne;
    @BindView(R.id.txt_info_two)
    TextView txtInfoTwo;

    @Override
    protected int setLayoutId() {
        return R.layout.fragment_vip_level_three;
    }

    @Override
    protected void initView() {
        setLoginInfo();
    }
    public void setLoginInfo(){
        btnLogin.post(new Runnable() {
            @Override
            public void run() {
                if (UserInfoGlobal.isLogin()) {
                    if (UserInfoGlobal.getUserLevel() >= 3) {
                        btnLogin.setText("已获等级");
                    } else {
                        btnLogin.setText("升级会员");
                    }
                    txtName.setText(UserInfoGlobal.getUserNick());
                } else {
                    btnLogin.setText("登录");
                }
            }
        });
    }
    public void setInfoData(String one, String two, String three, String four) {
        btnLogin.post(new Runnable() {
            @Override
            public void run() {
                txtInfoOne.setText("充值油卡实付累计" + one + "元\n或购买会员套餐" + two + "元");
                txtInfoTwo.setText("充值油卡实付累计" + three + "元\n或购买会员套餐" + four + "元");
                if (UserInfoGlobal.isLogin()) {
                    if (UserInfoGlobal.getUserLevel() >= 3) {
                        btnLogin.setText("已获等级");
                    } else {
                        btnLogin.setText("升级会员");
                    }
                    txtName.setText(UserInfoGlobal.getUserNick());
                } else {
                    btnLogin.setText("登录");
                }
            }
        });
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.btn_login)
    public void onViewClicked() {
        if (UI.toString(btnLogin).equals("登录")) {
            ((VipPacketActivity) getActivity()).gotoLogin();
        } else if (UI.toString(btnLogin).equals("已获等级")) {

        } else if (UI.toString(btnLogin).equals("升级会员")) {
            ((VipPacketActivity) getActivity()).goToBuyLevel();
        }
    }
}
